function batchPLI(inDir,outDir)
%inDir='/Users/matthew/workspace/data/mImaginery/data/';
%outDir='.';

%conds={'*_Rrest*','*_Rleft*','*_Rright*','*_Irest*','*_Ileft*','*_Iright*'};
conds={'*_Rest*'}
bands={[4 8],[8 13],[13 30],[30 50]};
bandLabels={'theta','alpha','beta','gamma'};

for j=1:length(bands) 
    for i=1:length(conds)
        pliXSubjs=pliXband(inDir,conds{i},bands{j});
        outfile=strcat(bandLabels{j},conds{i}(2:end-1));
        savePLIxSubjs(fullfile(outDir,outfile),pliXSubjs);
    end
end

function savePLIxSubjs(outfile,pliXSubjs)
save(outfile,'pliXSubjs');

function [pliXSubjs]=pliXband(inDir,cond,band)

filter=fullfile(inDir,cond);
files=dir(filter);
nSubjs=length(files);
load(fullfile(inDir,files(1).name),'data');
nCh=length(data.label);
pliXSubjs=zeros(nSubjs,nCh,nCh);
for i=1:nSubjs
    load(fullfile(inDir,files(i).name),'data');
    bf_data=selectBand(data,band);
    pliXSubjs(i,:,:)=pliXtrial(bf_data);
end